﻿<Window x:Class="TeF.Runner.UI.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:RunnerUI="clr-namespace:TeF.Runner.UI" xmlns:Icons="clr-namespace:TeF.Runner.UI.Controls.Icons"
        xmlns:System="clr-namespace:System;assembly=mscorlib" Title="TeF Runner" 
        MinWidth="800" MinHeight="600"
        Width="800" Height="600"
        WindowStartupLocation="CenterScreen"
        Icon="App.ico">
    <Window.Resources>
        <RunnerUI:IconStateToColorConverter x:Key="iconStateToColorConverter" />
        <RunnerUI:TextStateToColorConverter x:Key="textStateToColorConverter" />
        <RunnerUI:SelectedItemsToLogConverter x:Key="selectedItemsToLogConverter" />

        <System:String x:Key="LoadTestAssemblies">Load Test Assemblies...</System:String>
        <System:String x:Key="UnloadAllTestAssemblies">Unload All Test Assemblies</System:String>
        <System:String x:Key="UnloadSelectedTestAssemblies">Unload Selected Test Assemblies</System:String>
        <System:String x:Key="RunSelectedTests">Run Selected Tests</System:String>
        <System:String x:Key="RunFailedTests">Run Failed Tests</System:String>
        <System:String x:Key="RunAllTests">Run All Tests</System:String>
        <System:String x:Key="StopTests">Stop Running Tests</System:String>
        <System:String x:Key="Exit">Exit</System:String>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Menu Grid.Row="0">
            <MenuItem Header="File">
                <MenuItem Header="{StaticResource ResourceKey=LoadTestAssemblies}" Command="{Binding Path=LoadTestAssemblies}">
                    <MenuItem.Icon>
                        <Icons:Load/>
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="{StaticResource ResourceKey=UnloadSelectedTestAssemblies}" Command="{Binding Path=UnloadSelectedTestAssemblies}">
                    <MenuItem.Icon>
                        <Icons:Unload />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="{StaticResource ResourceKey=UnloadAllTestAssemblies}" Command="{Binding Path=UnloadAllTestAssemblies}">
                    <MenuItem.Icon>
                        <Icons:UnloadAll/>
                    </MenuItem.Icon>
                </MenuItem>
                <Separator/>
                <MenuItem Header="{StaticResource ResourceKey=Exit}" Command="{Binding Path=Exit}"/>
            </MenuItem>
            <MenuItem Header="Test">
                <MenuItem Header="{StaticResource ResourceKey=RunSelectedTests}" Command="{Binding Path=RunSelectedTests}">
                    <MenuItem.Icon>
                        <Icons:Run/>
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="{StaticResource ResourceKey=RunFailedTests}" Command="{Binding Path=RunFailedTests}">
                    <MenuItem.Icon>
                        <Icons:RunFailed/>
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="{StaticResource ResourceKey=RunAllTests}" Command="{Binding Path=RunAllTests}">
                    <MenuItem.Icon>
                        <Icons:RunAll/>
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="{StaticResource ResourceKey=StopTests}" Command="{Binding Path=StopTests}">
                    <MenuItem.Icon>
                        <Icons:Stop/>
                    </MenuItem.Icon>
                </MenuItem>
            </MenuItem>
        </Menu>

        <ToolBar Grid.Row="1">
            <Button ToolTip="{StaticResource ResourceKey=LoadTestAssemblies}" Command="{Binding Path=LoadTestAssemblies}">
                <Icons:Load/>
            </Button>
            <Button ToolTip="{StaticResource ResourceKey=UnloadSelectedTestAssemblies}" Command="{Binding Path=UnloadSelectedTestAssemblies}">
                <Icons:Unload/>
            </Button>
            <Button ToolTip="{StaticResource ResourceKey=UnloadAllTestAssemblies}" Command="{Binding Path=UnloadAllTestAssemblies}">
                <Icons:UnloadAll/>
            </Button>
            <Separator/>
            <Button ToolTip="{StaticResource ResourceKey=RunSelectedTests}" Command="{Binding Path=RunSelectedTests}">
                <Icons:Run/>
            </Button>
            <Button ToolTip="{StaticResource ResourceKey=RunFailedTests}" Command="{Binding Path=RunFailedTests}">
                <Icons:RunFailed/>
            </Button>
            <Button ToolTip="{StaticResource ResourceKey=RunAllTests}" Command="{Binding Path=RunAllTests}">
                <Icons:RunAll/>
            </Button>
            <Button ToolTip="{StaticResource ResourceKey=StopTests}" Command="{Binding Path=StopTests}">
                <Icons:Stop/>
            </Button>
        </ToolBar>

        <StatusBar Grid.Row="3">
            <TextBlock TextAlignment="Left" HorizontalAlignment="Left"/>
        </StatusBar>
        
        <Grid Grid.Row="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition MinWidth="250" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition MinWidth="500" />
            </Grid.ColumnDefinitions>

            <TreeView Grid.Column="0" 
                      ItemsSource="{Binding Assemblies}"
                      Name="_treeViewTests">
                <TreeView.ItemTemplate>
                    <HierarchicalDataTemplate ItemsSource="{Binding Items}">
                        <StackPanel Orientation="Horizontal">
                            <Ellipse Width="10" Height="10" VerticalAlignment="Center" Margin="0,0,4,0">
                                <Ellipse.Fill>
                                    <SolidColorBrush Color="{Binding Path=State, Converter={StaticResource iconStateToColorConverter}}"/>
                                </Ellipse.Fill>
                            </Ellipse>
                            <TextBlock Text="{Binding Name}">
                                <TextBlock.Foreground>
                                    <SolidColorBrush Color="{Binding Path=State, Converter={StaticResource textStateToColorConverter}}"/>
                                </TextBlock.Foreground>
                            </TextBlock>
                        </StackPanel>
                    </HierarchicalDataTemplate>
                </TreeView.ItemTemplate>
                <TreeView.ItemContainerStyle>
                    <Style TargetType="{x:Type TreeViewItem}">
                        <Setter Property="IsExpanded" Value="{Binding IsExpanded}"/>
                        <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/>
                    </Style>
                </TreeView.ItemContainerStyle>
            </TreeView>

            <TextBox Grid.Column="2"
                 IsReadOnly="True" 
                 TextWrapping="Wrap" AcceptsReturn="True" 
                 Text="{Binding Path=SelectedItems, Converter={StaticResource selectedItemsToLogConverter}}"/>

            <GridSplitter Grid.Column="1" 
                      Grid.RowSpan="3"
                      Width="5" HorizontalAlignment="Stretch" />

        </Grid>
    </Grid>
</Window>
